
//封闭函数 直接得到返回对象 
var wsLead = (function () {
    var link_status=false;
    /**
     * 为系统封装Websoket统一接口
     */
    var ws_o = null;
    //ws地址在注册websocket时候指定
    var ws_url = "ws://10.10.61.38:9098/tms/ws";
    /**
     * 连接websocket
     * @param {*} url 
     * @param {*} userId 
     */
    function connectWS(url,userId){
        //if((!KgoUtil.objIsNull(url)) && (!KgoUtil.objIsNull(userId))){
            console.log(url);
            ws_url = url + "/"+ userId;
       // }
        if ('WebSocket' in window) {  
            //Websocket的连接  
            ws_o = new WebSocket(ws_url);//WebSocket对应的地址  
        }  
        else if ('MozWebSocket' in window) {  
            //Websocket的连接  
            ws_o = new MozWebSocket(ws_url);//SockJS对应的地址  
        }  
        else {  
            //SockJS的连接  
            ws_o = new SockJS(ws_url2);    //SockJS对应的地址  
        }  
        ws_o.onopen = onOpen;  
        ws_o.onmessage = onMessage;  
        ws_o.onerror = onError;  
        ws_o.onclose = onClose; 
    }


    function clearWord(){
        
    }
    /**
     * 打开连接
     * @param openEvt
     * @returns
     */
    function onOpen(openEvt) {        
        if(openEvt.isTrusted){   
            $('.kgo-message-status-sty').css("color","#5FB878")
        }else{
            layer.msg("系统于服务器建立通信失败！您将无法正常获取系统信息！");
            $('.kgo-message-status-sty').css("color","#FF5722")
        }
    }  
    /**
     * 消息接收
     * @param evt
     * @returns
     */
    function onMessage(evt) { 
        console.log("返回数据："+evt.data);
        KgoUtil.setState("broadcastSysMessageInfo",evt.data)
        KgoUtil.getState("broadcastSysMessage");
       // wsLead.doSend(evt.data);
    }  
    function onError() {  
        
    }  
    function onClose() { 
        
    }   
    return { 
    	connectWS : function(url,userId) {  
    		connectWS(url,userId);
        }     	
    };
})();




















